package com.tengju.bff.interfaces.manage.star.facade;

import com.tengju.bff.interfaces.covercharge.service.bestsign.impl.contract.BestSignContractService;
import com.tengju.user.application.archives.StarContractService;
import com.tengju.user.domain.model.sign.StarContractInfo;
import com.tengju.user.domain.model.user.UserIdCode;
import org.apache.logging.log4j.core.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SignFacade {

    private final StarContractService starContractService;
    private final BestSignContractService bestSignContractService;

    @Autowired
    public SignFacade(StarContractService starContractService, BestSignContractService bestSignContractService) {
        this.starContractService = starContractService;
        this.bestSignContractService = bestSignContractService;
    }

    public byte[] downloadContract(UserIdCode idCode, Integer starRole) {
        StarContractInfo starContractInfo = starContractService.getStarAgreementInfo(idCode, starRole);
        if (starContractInfo == null) {
            return null;
        }
        String transId = String.valueOf(UuidUtil.getTimeBasedUuid().toString());
        return bestSignContractService.contractDownload(transId, starContractInfo.getContractId());
    }
}
